<?php

namespace app\api\validate;

use app\common\model\reimbursement\ExpenseApplication;
use app\common\model\user\User;
use app\common\validate\BaseValidate;
use think\facade\Request;

class UserExpenseApplicationValidate extends BaseValidate
{
    public function sceneApply()
    {
        return $this->only(['expense_type_id','amount', 'description'])
            ->appendRule([
                'expense_type_id' => 'require|number',
                'amount' => 'require|float'
            ]);
    }

    public function sceneModify()
    {
        return $this->only(['id', 'checkUserApplication']);
    }

    public function checkUserApplication($value, $rule, $data)
    {
        $userId = Request::instance()->userId;
        if (!ExpenseApplication::where(['id' => $value, 'applicant_id' => $userId])->count()){
            return '无权操作该申请记录';
        }
        return true;
    }

    public function sceneDetail()
    {
        return $this->only(['id']);
    }
}